package com.rcm.dda.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.rcm.dda.model.RateKey;
import com.rcm.dda.model.RateKeyMapper;

@Repository("rateKeyDao")
public class RateKeyDao extends BaseDao {

	public List<RateKey> getAll() {
		String sql = "select r.WARP_KEY_ID, r.WARP_INS_LINE_CD, r.WRI_KEY_DES, r.WRI_FORM_LEVEL_CD, "
				+ "rd.WAR_KEY_SEQ_NBR, rd.WAR_ADD_KEY_DES, rd.WAR_CON_IND "
				+ "from WARP_RATEKEY r LEFT JOIN WARP_RATEKEY_ADD rd "
				+ "ON r.WARP_KEY_ID = rd.WARP_KEY_ID and r.WARP_INS_LINE_CD = rd.WARP_INS_LINE_CD "
				+ "ORDER BY r.WARP_KEY_ID, r.WARP_INS_LINE_CD";
		return getJdbcTemplate().query(sql, new RateKeyMapper());
	}

	public RateKey insert(RateKey rateKey) {
		String sql = "INSERT INTO WARP_RATEKEY (WARP_KEY_ID, WARP_INS_LINE_CD, WRI_KEY_DES, WRI_FORM_LEVEL_CD)"
				+ " VALUES (?, ?, ?, ?)";
		getJdbcTemplate().update(sql, rateKey.getWrapKeyId(),
				rateKey.getWrapInsLineCd(), rateKey.getWriKeyDes(),
				rateKey.getWriFormLevelCd());
		return rateKey;
	}

	public RateKey update(RateKey rateKey) {
		
		String sql = "UPDATE WARP_RATEKEY SET " + "WARP_KEY_ID = ?, "
				+ "WARP_INS_LINE_CD = ?, " + "WRI_KEY_DES = ?, "
				+ "WRI_FORM_LEVEL_CD = ? "
				+ "WHERE WARP_KEY_ID = ? AND WARP_INS_LINE_CD = ?";
		getJdbcTemplate().update(sql, rateKey.getWrapKeyId(),
				rateKey.getWrapInsLineCd(), rateKey.getWriKeyDes(),
				rateKey.getWriFormLevelCd(), rateKey.getWrapKeyId(),
				rateKey.getWrapInsLineCd());
		return rateKey;
	}

	public void delete(RateKey rateKey) {
		String sql = "DELETE FROM WARP_RATEKEY WHERE WARP_KEY_ID = ? AND WARP_INS_LINE_CD = ?";
		getJdbcTemplate().update(sql, rateKey.getWrapKeyId(),
				rateKey.getWrapInsLineCd());
	}
}
